import axios from '~/plugins/axios';
import { basicConfig } from '~/assets/js/config'

//缓存广告系列
export const saveAdSeries = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adseries/cache.do', preload || {})
};
//fb广告系列名称唯一性验证
export const fbAdGroupName = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/admanager/checkAdSeriesName.do', {
        params: preload || {}
    })
};
//gg广告系列名称唯一性验证
export const ggAdGroupName = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/admanager/google/checkAdSeriesName.do', {
        params: preload || {}
    })
};

//获取自定义受众
export const getCustomAudience = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/listCustomAudience.do', {
        params: preload || {}
    })
};
//获取类似受众
export const getSimilarAudience = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/listLookAlikeAudience.do', {
        params: preload || {}
    })
};
//获取以保存受众
export const getSavedAudience = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/listSavedAudience.do', {
        params: preload || {}
    })
};
//地区查询，参数name,before,after,limit
export const getAddr = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/listLocations.do', {
        params: preload || {}
    })
};
//细分定位全部查询
export const getAllPosition = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/targetingBrowse.do', {
        params: preload || {}
    })
};
//细分定位建议列表查询
export const getSuggestionsPosition = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/targetingSuggestions.do', preload || {})
};
//细分定位条件查询
export const getSearchPosition = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/targetingSearch.do', {
        params: {
            name: preload.name
        }
    })
};

//新建已保存受众
export const createSaveAudience = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/createSavedAudience.do', preload || {})
};
//替换已保存受众
export const updateSaveAudience = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/updateSavedAudience.do', preload || {})
};
//获取覆盖人数
export const getAudienceCount = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/reachestimate.do', preload || {})
};

//查询语言列表 参数：name
export const getLanguage = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/listLanguage.do', {
        params: {
            name: preload.name
        }
    })
};

//主页列表
export const getHomePageList = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/listPage.do', preload || {})
};

export const getAudienceDetail = function({commit, state}, preload) {
    return axios.get('http://localhost:8000/mock/audiencedetails/audience1.json', {
        params: preload || {}
    })
};

//发布广告
export const postAd = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/admanager/create.do', preload || {})
};

//缓存广告
export const cacheAd = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/ad/cache.do', preload || {})
};

//上传广告图片
export const uploadAdImg = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/ad/uploadImg.do', preload || {})
};

//上传广告视频
export const uploadAdVideo = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/ad/uploadVideo.do', preload || {})
};

//请求广告视频预览图
export const getAdVideoImg = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/assets/img/getUrlByKey.do', preload || {})
};

//根据广告ID查询广告
export const getAdById = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/ad/listAdById.do', preload || {})
};

//编辑广告
export const updateAdData = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/ad/updateAd.do', preload || {})
};

//根据广告ID查询广告组--fb
export const getAdGroupById = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/adgroup/listAdGroupById.do', preload || {})
};
//编辑广告组--fb
export const editAdGroup = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/adgroup/updateAdGroup.do', preload || {})
};


//获取广告系列缓存接口
export const adSeriesCacheValue = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/admanager/adSeriesCacheValue.do', {
        params: preload || {}
    })
};

//获取广告组缓存接口--默认值接口
export const adGroupCacheValue = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/admanager/adGroupCacheValue.do', {
        params: preload || {}
    })
};

//验证URL
export const verifyUrlFB = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/ad/verifyWebUrl.do', preload || {})
};

/***
    谷歌接口
***/

//验证URL
export const verifyWebUrl = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/admanager/google/verifyWebUrl.do', preload || {})
};

//获取广告组缓存接口--默认值接口
export const ggGroupCacheValue = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/admanager/google/adGroupCacheValue.do', {
        params: preload || {}
    })
};

//查询谷歌受众语言
export const ggLanguageList = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/google/listLanguage.do', {
        params: preload || {}
    })
};

//查询谷歌受众关键词
export const ggKeyWordsList = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/google/listKeyWords.do', {
        params: preload || {}
    })
};

//查询谷歌推荐关键词
export const getSuggestionsKeywords = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/google/suggestionsKeywords.do', {
        params: preload || {}
    })
};


//查询谷歌受众地区
export const ggLocationsList = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/adset/audience/google/listLocations.do', {
        params: preload || {}
    })
};


//谷歌创建广告
export const ggCreateAd = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/admanager/google/create.do', preload || {})
};

//查询所有国家编码接口
export const getAllCountryCode = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/admanager/google/listCountryCode.do', preload || {})
};

//查询预计成效
export const getEsimate = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/adset/audience/google/reachEstimate.do', preload || {})
};

//更新google广告
export const updateGgAd = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/google/ad/update', preload || {})
};

//查询google广告
export const getGoogleAd = function({commit, state}, preload) {
    return axios.get(basicConfig.baseUrl + '/manager/google/ad/detail', {
        params: preload || {}
    })
};

//根据广告ID查询广告组--gg
export const getGgAdGroupById = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/google/adgroup/listAdGroupById', preload || {})
};
//编辑广告组--gg
export const editGgAdGroup = function({commit, state}, preload) {
    return axios.post(basicConfig.baseUrl + '/manager/google/adGroup/update/content', preload || {})
};